home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Jugar con las fuentes / ClipText / ClipText.cs next >
Encoding:
Text File  |  2002-05-10  |  1.9 KB  |  61 lines

  1. //---------------------------------------
  2. // ClipText.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class ClipText: FontMenuForm
  10. {
  11.      public new static void Main()
  12.      {
  13.           Application.Run(new ClipText());
  14.      }
  15.      public ClipText()
  16.      {
  17.           Text = "Recortar texto";
  18.           Width *= 2; 
  19.           strText = "Recortar texto";
  20.           font = new Font("Times New Roman", 108, FontStyle.Bold);
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           GraphicsPath path = new GraphicsPath();
  25.           float fFontSize = PointsToPageUnits(grfx, font);
  26.  
  27.                // A±adir texto al trazado.
  28.  
  29.           path.AddString(strText, font.FontFamily, (int) font.Style,
  30.                          fFontSize, new PointF(0, 0), new StringFormat());
  31.  
  32.                // Definir la regi≤n de recorte.
  33.  
  34.           grfx.SetClip(path);
  35.  
  36.                // Obtener los lφmites del trazado y centrar la regi≤n de recorte.
  37.  
  38.           RectangleF rectfBounds = path.GetBounds();
  39.           
  40.           grfx.TranslateClip(
  41.                          (cx - rectfBounds.Width) / 2 - rectfBounds.Left,
  42.                          (cy - rectfBounds.Height) / 2 - rectfBounds.Top);
  43.  
  44.                // Dibujar lφneas recortadas.
  45.  
  46.           Random rand = new Random();
  47.  
  48.           for (int y = 0; y < cy; y++)
  49.           {
  50.                Pen pen = new Pen(Color.FromArgb(rand.Next(255),
  51.                                                 rand.Next(255),
  52.                                                 rand.Next(255)));
  53.  
  54.                grfx.DrawBezier(pen, new Point(0, y),
  55.                                     new Point(cx / 3, y + cy / 3),
  56.                                     new Point(2 * cx / 3, y - cy / 3),
  57.                                     new Point(cx, y));
  58.           }
  59.      }
  60. }
  61.